package edu.byu.intex2.data;

import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.text.DecimalFormat;
import javax.swing.JFrame;

/**
 * Calls application wide methods.
 * @author Brady
 */
public class Controller {

    /////////////////////////////////////////////
    ///   Singleton code
    private static Controller instance = null;

    /** Creates a new instance of EmployeeDAO */
    private Controller() {
    }//constructor

    /** Retrieves the single instance of this class */
    public static synchronized Controller getInstance() {
        if (instance == null) {
            instance = new Controller();
        }
        return instance;
    }//getInstance

    /** Center the JFrame */
    public void center(JFrame frame) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Point center = ge.getCenterPoint();
        Rectangle bounds = ge.getMaximumWindowBounds();
        int w = frame.getWidth();
        int h = frame.getHeight();
        int x = center.x - w / 2, y = center.y - h / 2;
        frame.setBounds(x, y, w, h);
        frame.validate();
    }

    public static double roundTwoDecimals(double d) {
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        return Double.valueOf(twoDForm.format(d));
    }
}
